package edu.wong.pro.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.persistence.Id;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;

import com.opensymphony.xwork2.ActionSupport;

import edu.wong.pro.iservice.IMember;
import edu.wong.pro.model.Member;

public class MemberAction extends ActionSupport{
	private String memID;
	private IMember iMember;
	public String getMemID() {
		return memID;
	}
	public void setMemID(String memID) {
		this.memID = memID;
	}
	public IMember getiMember() {
		return iMember;
	}
	public void setiMember(IMember iMember) {
		this.iMember = iMember;
	}
	
	public void findMemberByID() throws IOException{
		HttpServletResponse response = ServletActionContext.getResponse();
		Member member = iMember.findMemberByID(memID);
		JSONArray jsonArray = JSONArray.fromObject(member);
	    response.setCharacterEncoding("utf-8");
  		PrintWriter out = response.getWriter();
  		out.print(jsonArray);
	}
	
	public void getStatisticData() throws IOException{
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
		String flag = request.getParameter("flag");
		HttpServletResponse response = (HttpServletResponse) ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter writer  =  response.getWriter();
		writer.print(iMember.getStatistics(flag));
		writer.flush();
		writer.close();
		
	}
	
}
